package com.zmcc.service.impl;

import com.google.gson.Gson;
import com.zmcc.entity.VerifTemplate;
import com.zmcc.entity.common.CommonRequest;
import com.zmcc.service.IVerifRequest;

import java.util.HashMap;
import java.util.Map;

public class VerifRequestCommercial implements IVerifRequest {

    private final static String url = "https://dev.cmccopen.cn/api";

    private static VerifRequestCommercial verifRequestCommercial;

    public static VerifRequestCommercial getInstance() {
        if(verifRequestCommercial == null){
            verifRequestCommercial = new VerifRequestCommercial();
        }
        return verifRequestCommercial;
    }


    @Override
    public CommonRequest getVerifBindSendRequest(VerifTemplate template) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/verif" + "/bind");
        request.setBody(new Gson().toJson(template));
        return request;
    }

    @Override
    public CommonRequest getVerifUnBindSendRequest(String requestid, String subscriptionid, String dn, String checkdn) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/verif" + "/unbind");
        Map<String ,String> bodyMap = new HashMap<>();
        bodyMap.put("requestid",requestid);
        bodyMap.put("subscriptionid",subscriptionid);
        bodyMap.put("dn",dn);
        bodyMap.put("checkdn",checkdn);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

    @Override
    public CommonRequest getVerifQueryStatusRequest(String requestid, String servicecode, String dn, String checkNumber) {
        CommonRequest request = new CommonRequest();
        request.setUrl(url+"/v1" + "/verif" + "/query"+"/status");
        Map<String ,String> bodyMap = new HashMap<>();
        bodyMap.put("requestid",requestid);
        bodyMap.put("servicecode",servicecode);
        bodyMap.put("dn",dn);
        bodyMap.put("checkNumber",checkNumber);
        request.setBody(new Gson().toJson(bodyMap));
        return request;
    }

}
